cmake_minimum_required(VERSION 3.5)
project(agv_navigate)

SET(CMAKE_BUILD_TYPE "Debug")  
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++17)

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(agv_msgs REQUIRED)
find_package(agv_actions REQUIRED)
find_package(agv_srvs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread system)
find_package(shared_parameters REQUIRED)
#find_package(generate_parameters_header REQUIRED)

execute_process(
  COMMAND git rev-parse --short HEAD
  OUTPUT_VARIABLE GIT_HASH
  OUTPUT_STRIP_TRAILING_WHITESPACE
)
 
if(NOT GIT_HASH)
  set(GIT_HASH "unknown_hash")
endif()

add_definitions(-DVERSION_HASH=\"${GIT_HASH}\")

include_directories(
  include
  include/agvNavigate
  include/agvNavigate/opInclude
  include/agvNavigate/publicInterfaceInc
  include/agvNavigate/helpInc
  include/agvWorld
  include/driveToPath
)  

file(GLOB_RECURSE SRCS 
  agvNavigate/*.cpp
  agvNavigate/opSrc/*.cpp
  agvNavigate/publicInterfaceSrc/*.cpp
  agvNavigate/helpSrc/*.cpp
  )

file(GLOB_RECURSE AGVWORLD 
  agvWorld/*.cpp)

## Declare a C++ library
add_library(agvWorld SHARED
  ${AGVWORLD}
)

# Set dependencies for agvWorld library
ament_target_dependencies(agvWorld
  "rclcpp"
  "geometry_msgs"
  "shared_parameters"
)

add_executable(${PROJECT_NAME} ${SRCS})

# Link local library
target_link_libraries(${PROJECT_NAME}
  ${Boost_LIBRARIES}
  agvWorld
)

## Specify libraries to link a library or executable target against
ament_target_dependencies(${PROJECT_NAME}
  "tf2_ros"
  "tf2_geometry_msgs"
  "std_msgs"
  "std_srvs"
  "agv_actions"
  "nav_msgs"
  "agv_msgs"
  "agv_srvs"
  "rclcpp"
  "geometry_msgs"
  "shared_parameters"
)

# add_executable(drive_to_path driveToPath/drive_to_path.cpp)

# Link local library
# target_link_libraries(drive_to_path
#  Private agvWorld
#)

# ament_target_dependencies(drive_to_path
#   "tf2_ros"
#   "std_msgs"
#   "std_srvs"
#   "agv_actions"
#   "nav_msgs"
#   "agv_msgs"
#   "agv_srvs"
#   "rclcpp"
#   "geometry_msgs"
# )

#message(STATUS "Run generate parameters head script")
#generate_parameters_header(${PROJECT_NAME} ${PROJECT_NAME})

ament_export_include_directories(include)

# Export the library
# ament_export_targets(export_agvWorld HAS_LIBRARY_TARGET)
ament_export_dependencies(rclcpp rclpy std_msgs roslib geometry_msgs tf2_ros agv_msgs agv_actions agv_srvs)
ament_package()

install(TARGETS ${PROJECT_NAME} 
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY launch config
  DESTINATION share/${PROJECT_NAME}
)

install(TARGETS ${PROJECT_NAME} agvWorld
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)
